package com.exchange.controller.app.user;

import com.exchange.controller.BaseController;
import com.exchange.interceptor.AppUserTokenInterceptor;
import com.jfinal.aop.Before;
import com.jfinal.aop.Clear;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Ret;
import com.jfinal.upload.UploadFile;

/**
 * 功能说明：有关用户的控制器
 * @version 1.0
 */

@Before({UserValidator.class,AppUserTokenInterceptor.class})
public class UserController extends BaseController {

	@Inject
	UserService service;
	
	/**
	 * 发送注册验证码
	 * @param type 验证码发送类型(手机1/邮箱2)
	 * @param to 发送到哪
	 */
	@Clear(AppUserTokenInterceptor.class)
	public void sendRegisterMessage(int type, String to) {
		Ret ret = service.sendRegisterMessage(type, to);
		renderJson(ret);
	}
	
    /**
     * 用户的注册
     * @return
     */
	@Clear(AppUserTokenInterceptor.class)
    public void register(String account, String password, String to, String vcode, int type, String invitationCode) {
    	Ret ret = service.register(account, password, to, vcode, type, invitationCode);
    	renderJson(ret);
    }
	
	/**
	 * 用户登录(用户具体的登陆动作)
	 */
	@Clear(AppUserTokenInterceptor.class)
    public void login(String account, String password) {
		Ret ret = service.login(account, password);
		renderJson(ret);
    }
	
	/**
	 * 发送忘记密码的验证码
	 */
	@Clear(AppUserTokenInterceptor.class)
	public void fCaptcha(int type, String account) {
		Ret ret = service.fCaptcha(type, account);
		renderJson(ret);
    }

	/**
     * 忘记密码
     */
	@Clear(AppUserTokenInterceptor.class)
    public void forget(String account, String vcode, String newPassword) {
    	Ret ret = service.forget(account, vcode, newPassword);
		renderJson(ret);
    }
	
    /**
     * 修改密码
     */
    public void mdfLoginPassword(String oldPassword, String newPassword) {
    	Ret ret = service.mdfLoginPassword(getAttr("user"), getAttr("token"), oldPassword, newPassword);
    	renderJson(ret);
    }
	
    /**
     * 用户修改交易密码
     */
    public void mdfTradePassword(String vcode, String newTradePassword) {	
		Ret ret = service.mdfTradePassword(getAttr("user"), getAttr("token"), vcode, newTradePassword);
		renderJson(ret);
    }

    /**
     * 修改资金密码发送验证码
     */
    public void captcha() {
    	Ret ret = service.captcha(getAttr("user"), getAttr("token"));
		renderJson(ret);
    }

    /**
    * 交易授权
    */
	public void authorization(String cipher) {
		Ret ret = service.authorization(getAttr("user"), getAttr("token"), cipher);
		renderJson(ret);
	}

	/**
	 * 用户退出系统
	 */
	public void logout() {
		Ret ret = service.logout(getAttr("token"));
		renderJson(ret);
	}

	/**
	 * 绑定邮箱或电话验证码
	 */
	public void bCaptcha(int type, String to) {
		Ret ret = service.bCaptcha(getAttr("user"), type, to);
		renderJson(ret);
	}

	/**
	 * 绑定
	 */
	public void bind(int type, String to, String vcode) {
		Ret ret = service.bind(getAttr("user"), type, to, vcode);
		renderJson(ret);
	}
   
	/**
	 * 上传用户头像
	 */
	public void upload(UploadFile header) {
		Ret ret = service.upload(getAttr("user"), header);
		renderJson(ret);
	}

   	/**
   	 * 用户邀请码补填
   	 * 注册时用户如果没有输入邀请码
   	 */
   	public void addInvitationCode(String invitationCode) {
   		Ret ret = service.addInvitationCode(getAttr("user"), invitationCode);
		renderJson(ret);
   	}
   	
   	
   	
	

}